package com.study.java.classloader.myClassLoader;

import com.study.java.classloader.myClassLoader.FileSystemClassLoader.FileSystemClassLoader;

/**
* @Name: ThreadContextClassLoader
* @Description: 线程上下文类加载器测试
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-9 下午6:39:20 
* @Version: V1.0
 */
public class ThreadContextClassLoader {
	
	public static void main(String[] args) throws Exception {
		//获取当前线程的类加载器
		ClassLoader loader = ThreadContextClassLoader.class.getClassLoader() ;
		System.out.println(loader); //AppClassLoader
		//获取当前线程的类加载器
		ClassLoader loader2 = Thread.currentThread().getContextClassLoader() ;
		System.out.println(loader2); //AppClassLoader
		//修改当前线程的类加载器
		Thread.currentThread().setContextClassLoader(new FileSystemClassLoader("d:/myjava")) ;
		//获取当前线程的类加载器
		ClassLoader loader3 = Thread.currentThread().getContextClassLoader() ;
		System.out.println(loader3); //FileSystemClassLoader
		//加载指定的字节码文件
		Class<?> clazz = loader3.loadClass("HelloWorld") ;
		System.out.println(clazz);
		//获取字节码文件对象的类加载器
		System.out.println(clazz.getClassLoader()); //FileSystemClassLoader
	}

}
